package com.ruoyi.api;

import com.ruoyi.biz.domain.BizClass;
import com.ruoyi.biz.domain.FrontUser;
import com.ruoyi.biz.mapper.BizClassMapper;
import com.ruoyi.biz.mapper.FrontUserMapper;
import com.ruoyi.biz.service.IBizClassService;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/class")
@Slf4j
public class ApiClassController {
    @Resource
    private IBizClassService classService;

    @Resource
    private FrontUserMapper frontUserMapper;

    @Resource
    private BizClassMapper classMapper;

    /*加入班级*/
    @PostMapping("/join")
    public AjaxResult joinClass(@RequestBody String classNumber){
        log.info("加入班级，班级码：{}",classNumber);
        Boolean b = classService.joinClass(classNumber);

        return AjaxResult.success(b);
    }

    /*
    * 根据课程id查询班级学生
    * */
    @GetMapping("/query")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult queryClassStudent(Long courseId){
        log.info("课程id:{}",courseId);
        AjaxResult result = AjaxResult.success();
        List<FrontUser> frontUsers = frontUserMapper.selectByCourseId(courseId);
        BizClass bizClass = classMapper.selectByCourseId(courseId);

        result.put("list",frontUsers);
        result.put("class",bizClass);
        return result;
    }
}
